package com.zhd.grpcclient.grpc;

import io.grpc.Channel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import proto.OrderGrpc;
import proto.OrderOuterClass;

/**
 * @author zhanghuadi
 * @version 1.0
 * @date 2021/1/10 0010 11:00
 */
@Service
public class OrderGrpcService {

    private final static Logger LOGGER = LoggerFactory.getLogger(OrderGrpcService.class);

    //@GrpcClient("https://120.55.59.54:30111")
    private Channel serverChannel;

    /**
     * @return void
     * @description: 用于远程调用order服务
     * @author zhanghuadi
     * @date 2021/1/10 0010 11:16
     * @version 1.0
     */
    public void orderListReq() {
        final OrderGrpc.OrderBlockingStub orderBlockingStub = OrderGrpc.newBlockingStub(serverChannel);
        //构造入参
        final OrderOuterClass.OrderListReq req = OrderOuterClass.OrderListReq.newBuilder()
                .setStatus(10)
                .build();
        //远程调用
        final OrderOuterClass.OrderListRes res = orderBlockingStub.orderList(req);
        LOGGER.info("请求结果:" + res.getMessage());
    }

    public void orderDetailReq() {
        final OrderGrpc.OrderBlockingStub orderBlockingStub = OrderGrpc.newBlockingStub(serverChannel);
        OrderOuterClass.OrderDetailReq req = OrderOuterClass.OrderDetailReq.newBuilder()
                .setOrderId("3a9e562f-5096-11eb-b085-5e2d5724df99")
                .setCompanyId("W00000000177")
                .build();
        //远程调用
        final OrderOuterClass.OrderDetailRes orderDetailRes = orderBlockingStub.orderDetail(req);
        LOGGER.info("请求结果:" + orderDetailRes.getMessage());
    }

}
